function twmodalfn (e, flag, con) {
  var _this = $(e)
  if (flag) {
    $('body').addClass('tw-modal-open')
    _this.find('.u-des').html(con)
    _this.addClass('show').show()
  } else {
    _this.removeClass('show').hide()
    _this.find('.u-des').html('')
    $('body').removeClass('tw-modal-open')
  }
}

window.onload = function () {
  var ms = new Date().getTime()
  $('#app-login-vcode-img').attr('src', 'http://192.168.113.248:8080/scorequery/vc.jsp?a=' + ms)
}

$('.tw-modal-errtip .u-btn,.tw-modal-errtip .close').on('click', function () {
  // window.location.href="http://192.168.113.248:8080/scorequery/studentQuery/index2";
  twmodalfn('.tw-modal-errtip', false)
})
// 换验证码
$('#size14').on('click', function () {
  var ms = new Date().getTime()
  $('#app-login-vcode-img').attr('src', 'http://192.168.113.248:8080/scorequery/vc.jsp?a=' + ms)
})

// 提交查询
$('#subBtn').on('click', function () {
  if (checkParams()) {
    // $("#loginForm").submit();
    twmodalfn('.tw-modal-errtip', true)
  }
})

$('#examNo').bind('input propertychange', function () {
  var value = $('#examNo').val().replace(/[\W]/g, '')
  $('#examNo').val(value)
})

$('#loginForm .input').focus(function () {
  $('.form-error').removeClass('form-error')
  $('.form-errtxt').text('')
  $('.login_err').text('')
})

function checkParams () {
  $('.form-error').removeClass('form-error')
  var examNo = $('#examNo').val()
  if (examNo == undefined || examNo == '' || examNo == null) {
    $('.examNo_err').addClass('form-error')
    $('.examNo_errtxt').text('考试号不能为空')
    return false
  }
  if ($('#name').length > 0 && !$('#name').parent().parent().is(':hidden')) {
    $('.form-error').removeClass('form-error')
    var name = $('#name').val()
    if (name == undefined || name == '' || name == null) {
      $('.name_err').addClass('form-error')
      $('.name_errtxt').text('姓名不能为空')
      return false
    }
  }

  var validCode = $('#validCode').val()
  if (validCode == undefined || validCode == '' || validCode == null) {
    $('.validCode_err').addClass('form-error')
    $('.validCode_errtxt').text('请输入验证码')
    return false
  }
  return true
}
